package ru.sgu.diploma.practic;

import org.junit.Test;
import ru.sgu.diploma.practic.domain.model.GeometricModel;
import ru.sgu.diploma.practic.domain.model.Point;
import ru.sgu.diploma.practic.service.ImageConstructor;
import ru.sgu.diploma.practic.service.impl.ImageConstructorImpl;
import ru.sgu.diploma.practic.utils.GeometricModelUtils;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
 * User: datmakin
 * Date: 13.03.11
 * Time: 20:33
 */

public class ImageConstructorTestCase {

    @Test
    public void printImage() {
        ImageConstructor imageConstructor = new ImageConstructorImpl();

        GeometricModel geometricModel = new GeometricModel();
        List<Point> pointList = new LinkedList<Point>();

        //for (int size = -2; size < 2; size++) {
            for (int i = -200; i < 200; i++) {
                pointList.add(new Point(i, i));
            }
        //}
        //for (int size = -2; size < 2; size++) {
            for (int i = -200; i < 200; i++) {
                pointList.add(new Point(i, -i));
            }
        //}

        geometricModel.setPointList(pointList);

        geometricModel.setImageResolution(GeometricModelUtils.calculateResolution(geometricModel));

        BufferedImage bufferedImage = imageConstructor.construct(geometricModel);
        BufferedImage scaledBufferedImage = imageConstructor.constructWithScale(geometricModel, 4);



        try {
            File outputfile = new File("testoutput/saved.png");
            outputfile.mkdirs();
            ImageIO.write(bufferedImage, "png", outputfile);
            File scaledOutputfile = new File("testoutput/scaledSaved.png");
            scaledOutputfile.mkdirs();
            ImageIO.write(scaledBufferedImage, "png", scaledOutputfile);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
